package org.example.blog.model;

import lombok.Data;
import org.example.blog.constants.Constants;

@Data
public class Result<T> {
    private int code; //200 表示业务请求成功 -1 失败
    private String errMsg;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setData(data);
        result.setErrMsg("");
        return result;
    }

    public static <T> Result<T> fail(String errMsg) {
        Result<T> result = new Result<T>();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T> Result<T> fail(String errMsg, T data) {
        Result<T> result = new Result<T>();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
}
